package com.keta.foundation.entity;

import java.util.ArrayList;
import java.util.List;


import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Range;

/**
 * @author 罗兵
 * 字典主题DICT只有一层  字典项ITEM为树形结构
 */
@Entity
@Table(name = "t_dict")
public class Dict {
	
	private static final long serialVersionUID = 3114541237317138260L;
	
	public static final String TYPE_DICT ="DICT";
	public static final String TYPE_ITEM ="ITEM";

	/*
	 * 字典自增ID
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	
	/*
	 * 字典类型  包括字典主题  和  字典项
	 */
	@Column(length = 32)
	private String type;
	
	/**
	 * 字典码
	 */
	@Column(length = 32)
	private String code;
	
	/**
	 * 字典值
	 */
	@Column(length = 32)
	private String name;
	
	
	/**
	 * 备注信息
	 */
	@Column(length = 32)
	private String remark;
	
	/*
	 * 优先级、排序
	 */
	@NotNull
	@Range(min = 1, max = 999)
	@Column(length = 3, nullable = false)
	private Integer priority = 999;
	
	/*
	 * 父级字典
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "parentId")
	private Dict parent;

	/*
	 * 子级别字典
	 */
	@OneToMany(mappedBy = "parent")
	@OrderBy("priority ASC")
	private List<Dict> children = new ArrayList<Dict>();

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Integer getPriority() {
		return priority;
	}

	public void setPriority(Integer priority) {
		this.priority = priority;
	}

	public Dict getParent() {
		return parent;
	}

	public void setParent(Dict parent) {
		this.parent = parent;
	}

	public List<Dict> getChildren() {
		return children;
	}

	public void setChildren(List<Dict> children) {
		this.children = children;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}
	
	
	
	
}
